import request from '@/utils/request';
import type {
    IBizIdPageRequest,
    ProductEpisodeIds,
    IPlayUrl,
} from '@/typings/api';
import type {IProduct, IChapter, IComment} from '@/typings/interface';

/**
 * 获取视频详情信息
 */
export function getDetail(videoId: number) {
    return request<IProduct>(`/product/v1/detail?id=${videoId}`);
}

/**
 * 查询视频是否购买过
 */
export function queryVideoState(videoId: number) {
    return request(`/order/v1/query_pay?id=${videoId}`);
}

/**
 * 获取视频章节列表
 */
export function getChapterList(videoId: number) {
    return request<IChapter[]>(`/product/v1/chapter?id=${videoId}`);
}

/**
 * 获取视频评分列表
 */
export function getCommentPage(req: IBizIdPageRequest) {
    return request<IComment, true>('/comment/v1/page', {
        data: req,
        method: 'POST',
    });
}

/**
 * 获取视频资料
 */
export function getMeterial(videoId: number) {
    return request<Pick<IProduct, 'ali_zip_url' | 'bd_zip_url' | 'note_url'>>(
        `/product/v1/material_by_id?id=${videoId}`
    );
}

/**
 * 获取视频播放url
 */
export function getPlayUrl(req: ProductEpisodeIds) {
    return request<IPlayUrl>('/getPlayUrl/v1/get_play_url', {
        data: req,
        method: 'POST',
    });
}

